﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Configurations;

namespace Konekcija.Core.Reporting.Mappings.Configurations
{
    public class CategorySetMap : ClassMap<CategorySet>
    {
        public CategorySetMap()
        {
            Schema("config");
            Table("CategorySets");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.Name).Nullable();
            Map(x => x.Description).Nullable();
            Map(x => x.DateCreated).Nullable();

            HasMany(x => x.Categories)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CategorySetId")
                .Cascade.None();

            HasManyToMany(x => x.Websites)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("CategorySetId")
                .ChildKeyColumn("WebsiteId")
                .Table("config.CategorySetsToWebsites");
        }
    }
}
